﻿<?php
class qqzan{
	function set($qq,$sid,$content){
		$this->qq=$qq;
		$this->sid=$sid;
		$this->content=$content;
	}
	function getnew(){
		if($this->sid){
            if(!isset($stop)){
            $url="http://m.qzone.com/get_feeds?g_tk=".time()."&res_type=0&refresh_type=2&format=json&sid=".$this->sid;
			$json=file_get_contents($url);
			$arr=json_decode($json,true);
			if(@array_key_exists('code',$arr) && $arr['code']==0){
				$shuos=$arr['data']['vFeeds'];
				foreach($shuos as $shuo){
                    if($this->is_comment($this->qq,$shuo['comment']['comments'])){
                    	$cellid=$shuo['id']['cellid'];
                        $type=$shuo['comm']['appid'];
						$curkey=urlencode($shuo['comm']['curlikekey']);
						$uinkey=urlencode($shuo['comm']['orglikekey']);
						$uin=$shuo['userinfo']['user']['uin'];
						$content=$this->content;
                        $this->addcomment($content,$uin,$cellid,$type,$uinkey,$curkey);
                        sleep(1);
                    }
				}
			}
            }
		}
	}

	
    function addcomment($content,$uin,$cellid,$type,$uinkey,$curkey){
        $post="res_id=$cellid&res_uin=$uin&format=json&res_type=$type&content=$content&busi_param=4%3d%265%3d$uinkey%266%3d$curkey%2616%3d0%2623%3d1%2630%3d1%26-100%3dappid:$type+typeid:0+feedtype:0+hostuin:".$this->qq."+feedskey:$cellid+&opr_type=addcomment&sid=".$this->sid;
		$url="http://m.qzone.com/operation/publish_addcomment?g_tk=1712466800";
		$json=$this->getcurl($url,$post);
        $arr=json_decode($json,true);
	}



	function getcurl($url,$post){
		$ch=curl_init($url);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		if($post){
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
		}
		$content = curl_exec($ch);
		curl_close($ch); 
		return $content;
	}

    function is_comment($uin,$arrs){
        if($arrs){
	    	foreach($arrs as $arr){
    	   		if($arr['user']['uin'] == $uin){
        			return false;
            		break;
        		}
    		}
        	return true; 
        }else{
        	return true; 
        }
	}
    
}
